package com.sleet.yuemiao.util;

import org.springframework.data.repository.init.ResourceReader;

import java.io.*;
import java.net.URL;

/**
 * @program: yuemiao
 * @ClassName ZoneUtl
 * @description:
 * @author: Liyongxing
 * @create: 2021-12-23 09:43
 **/
public class ZoneUtl {

    /**
     * 读取json文件，返回json串
     * @param
     * @return
     */
    public static String readJsonFile(InputStream inputStream) {
        String jsonStr = "";
        try {
            Reader reader = new InputStreamReader(inputStream,"utf-8");
            int ch = 0;
            StringBuffer sb = new StringBuffer();
            while ((ch = reader.read()) != -1) {
                sb.append((char) ch);
            }
            reader.close();
            jsonStr = sb.toString();
            return jsonStr;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
    public static InputStream loadJarFileByResource(String tarFileName) throws IOException {
        URL resource = ResourceReader.class.getClassLoader().getResource(tarFileName);
        String path = resource.toString();
        InputStream inputStream = resource.openStream();
        return inputStream;
    }
}
